const { program } = require("commander");
const path = require("path");
const htmlCodeGenerator = require("./htmlCodeGenerator");
const codeExtractor = require("./codeExtractor");
const codeConverter = require("./codeConverter");
const codeToProjectConverter = require("./codeToProjectConverter");

/**
 * @param {string} askContent 文本输入
 * @param {*} targetPath 指定生成目录
 */
async function main(askContent, targetPath) {
  // 生成html内容
  const htmlContent = await htmlCodeGenerator.generateHtmlContent(askContent);
  // 抽取html代码
  const htmlCode = codeExtractor.extractHtmlFromMarkdown(htmlContent);
  // html转换为ux
  const uxCode = codeConverter.convertToBlueOSCodeFromHtml(htmlCode);
  // 导出html工程
  codeToProjectConverter.exportCodeAsProject(uxCode, targetPath);
  console.log(`代码生成完成`);
}

program
  .version("1.0.0")
  .option("-s, --sentence <sentence>", "The input sentence")
  .option('-d, --directory <directory>', 'The output directory')
  .action((options) => {
    console.log(options.sentence);
    const targetPath = path.join(process.cwd(), options.directory)
    main(options.sentence, targetPath);
  });

program.parse(process.argv);

